package pkg.customer;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import HibernateBeans.ProductDetails;
import retail.bo.CustomerBo;

public class UpgradeAction extends Action {
	private CustomerBo customerBo;

	public CustomerBo getCustomerBo() {
		return customerBo;
	}
	public void setCustomerBo(CustomerBo customerBo){
		this.customerBo=customerBo;
	}
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		HttpSession session=request.getSession();
		DynaActionForm myForm=(DynaActionForm)form;
		System.out.println(myForm);
		if(myForm.getString("submit").equals("Upgrade")){
			boolean upgrade=customerBo.upgrade((String) session.getAttribute("username"), myForm.getString("pid"));
			if(upgrade)
				return mapping.findForward("success");
			else
				return mapping.findForward("failed");
		}
			
		String pid=myForm.getString("pid");
		List<ProductDetails>lp=customerBo.getUpgrades(pid);
		session.setAttribute("upgrades", lp);
		return mapping.findForward("upgrade");
	}

}
